/*
 * @Author: your name
 * @Date: 2021-09-07 18:35:19
 * @LastEditTime: 2021-10-13 10:56:20
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \ydzq\wa-manage-view\src\api\error.js
 */
export const InterceptResponse = (res) => {
  let { request, data } = res;
  // 判断若当前返回的请求头中携带对应的登录标识则将其保存至store中用于后方验证
  // authorization && window.$VueStore.commit("common/SET_AUTHORIZATION", authorization)
  // 当前结果集为文本时
  if (request.responseType == "text" && !data) return false;
  // 系统异常
  // if (data.code == 10) return window.$VueStore.dispatch("common/setError", {
  //   msg: "系统异常"
  // });
  // 920 - 用户未登录
  if (data.code == 920 || data.code == 922) {
    if (window.__POWERED_BY_QIANKUN__) { //主应用环境
      return window.$VueStore.commit("common/SET_LOGINBACK", true)
    } else {
      window.$store.commit("SETAUTHORIZATION", undefined);
      sessionStorage.removeItem("reqOption")
      window.alert(data.msg || '用户未登录');
      return false
    }
  }
  // 业务异常
  // if (data.code != 0) return window.$VueStore.dispatch("common/setExceptions", data);
  // 默认返回true
  return true;
}

export const handleError = (data) => {
  console.log(data);
  return true;
}

window.tkGlobalConfig = window.tkGlobalConfig || {};
window.tkGlobalConfig.InterceptResponse = window.tkGlobalConfig.InterceptResponse || InterceptResponse;
window.tkGlobalConfig.handleError = window.tkGlobalConfig.handleError || handleError;
window.tkGlobalConfig.isDeleteHeaderToken = true